package Socket_Chat;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class SocketClient3 {
	public static void main(String[] args) {
//		String host = args[0];
//		int port = Integer.valueOf(args[1]);		
		String host = "localhost";
		int port = 7777;
		
		Socket socket = null;
		OutputStream outputStream = null;
		InputStream inputStream = null;
		try {
			socket = new Socket(host, port);
			System.out.println("start Client host:"+host+" port:"+port);
			
			Thread thread = new Thread(new ChatClient(socket));
			thread.start();
			while(true){
				InputStream in = socket.getInputStream();
				int len = 0;
				while(len == 0) {
					len = in.available();
				}
				byte[] b = new byte[len];
				in.read(b);
				System.out.println(new String(b, "UTF-8"));
			}
			
			
			
			
			
			
		
		
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				outputStream.close();
				socket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		
		
		
		
	}
	
	
}
